<?php

//include_once ("../configure/configure.php");		//-- global var
include_once("./configure/admin.config.inc.php");	//--> global var
include_once("db.inc.php");						//--> db global var
include_once("Smarty.class.php");				//--> out template
include_once("Authority.php");					//--> Authority
//include_once("controlHeader.php");				//--> system control header
include_once ("Session.php");						//-- Session

//if ($_SERVER["HTTPS"] <> "on")   
//{   
//	$xredir="https://".$_SERVER["SERVER_NAME"]. $_SERVER["REQUEST_URI"];   
//	header("Location: ".$xredir);   
//}


$objSession	= new Session();				//-- session

/*----- check session -----*/
if($objSession->exist()) {
	$gid = $objSession->getGroupID();
	$uid = $objSession->getUserID();

}else{
	header("Location: ./login.php");
	exit;
}

if(isset($_GET["Lan"])){
	$arrLan = array("lan" => $_GET["Lan"]);
	$objSession->add($arrLan);
}

if($objSession->getLanguage() == "zh-CN"){
	include_once("zh-CN.inc.php");	//--> zh_CN
}else{
	include_once("en-US.inc.php");	//--> us_EN
}

if(isset($_GET['menuGid']) && isset($_GET['menuid'])){
	$menuGid 	= $_GET['menuGid'];
	$menuid 	= $_GET['menuid'];
	$id			= $_GET['id'];
}else{
	$menuGid 	= $_POST['menuGid'];
	$menuid 	= $_POST['menuid'];
	$id			= $_POST['id'];
}

if(isset($_POST['backurl']))
	$backurl = $_POST['backurl'];
else
	$backurl = $_SERVER['HTTP_REFERER'];

$objAuth 	= new Authority($objSession->getLanguage(), $uid);	//--> Authority

$navigation = 'Welcome';
$strSubFrameUrl = "templates_sys_en-US/welcome.htm";

$objAuth->setLan($objSession->getLanguage());

$arrMenuList = $objAuth->getMenuFromGroupID($gid);

if(isset($_GET['menuGid']) && isset($_GET['menuid']) && is_array($arrMenuList)){
	foreach ($arrMenuList as $cache){
		foreach ($cache as $arrValue){
			if($arrValue['mid'] == $_GET['menuid']){
				$strSubFrameUrl = $arrValue['url'] . "?menuGid=$menuGid&menuid=$menuid";
				
				$navigation = $arrValue['gname'] . ' > ' . $arrValue['mname'];
			}
		}
	}
}

/*----- out html -----*/
$smarty = new Smarty();	//-- out template
$smarty->template_dir = TEMPLATE_SYS_DIR;
$smarty->compile_dir  = COMPILE_SYS_DIR;

$smarty->assign('arrMenuList', $arrMenuList);
$smarty->assign('initGid', $menuGid);

$smarty->assign('userName', $objSession->getUserName());
$smarty->assign('navigation', $navigation);

$smarty->assign('subFrameUrl', $strSubFrameUrl);

$smarty->display('main.htm');
?>
